package com.acwing.lc.part1;

import java.util.ArrayList;
import java.util.List;

/**
 * @author rkc
 * @date 2022/9/9 16:54
 */
public class LC17电话号码的字母组合 {

    private final String[] ss = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    private List<String> ans = new ArrayList<>();
    private String digits;

    public List<String> letterCombinations(String s) {
        if (s.length() == 0) return ans;
        digits = s;
        dfs(0, new StringBuilder());
        return ans;
    }

    private void dfs(int u, StringBuilder sb) {
        if (u == digits.length()) {
            ans.add(sb.toString());
            return;
        }
        String s = ss[digits.charAt(u) - '0'];
        for (int i = 0; i < s.length(); i++) {
            sb.append(s.charAt(i));
            dfs(u + 1, sb);
            sb.deleteCharAt(sb.length() - 1);
        }
    }
}
